package servlet.announce;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import bean.control.AnnounceMgr;
import bean.entity.Announce;

@SuppressWarnings("serial")
public class ModifyAnnounceServlet extends HttpServlet {
	protected void doGet(HttpServletRequest req, HttpServletResponse resp)
			throws ServletException, IOException {
		HttpSession session = req.getSession();
		
		if (session.getAttribute("memId") != null && session.getAttribute("memId").equals("0")) {
			String annId = req.getParameter("id");
			Announce ann = AnnounceMgr.getAnnounceById(Long.parseLong(annId));
			
			req.setAttribute("ann", ann);
			req.getRequestDispatcher("./announce/modifyAnnounce.jsp").forward(req, resp);
		}
		else
			resp.sendRedirect("./index");
	}
	
	protected void doPost(HttpServletRequest req, HttpServletResponse resp)
			throws ServletException, IOException {
		req.setCharacterEncoding("utf-8");
		String annId = req.getParameter("id");
		String title = req.getParameter("title");
		String content = req.getParameter("content");
		
		AnnounceMgr.modifyAnnounceById(Long.parseLong(annId), title, content);
	}
}
